package com.probiz.estore.product.dao.impl;

import java.util.List;

import com.probiz.estore.common.model.product.SkuOption;
import com.probiz.estore.core.dao.impl.HibernateGenericDaoImpl;
import com.probiz.estore.product.dao.SkuOptionDao;
import com.probiz.estore.product.model.SkuOptionFullyModel;

/**
 * Dao implementation for SkuOption.
*/
public class SkuOptionDaoImpl extends HibernateGenericDaoImpl<SkuOption> implements SkuOptionDao {

	@SuppressWarnings("unchecked")
	public List<SkuOption> findSkuOptionsByProductType(Integer productTypeId) {
		List<SkuOption> skuOptions=findByHql("select ptso.skuOption from ProductTypeSkuOption ptso where ptso.productType.productTypeId=? order by ptso.sortOrder asc", productTypeId);
		return skuOptions;
	}
	
	@SuppressWarnings("unchecked")
	public List<SkuOption> findActiveSkuOptionsByProductType(Integer productTypeId){
		List<SkuOption> skuOptions=findByHql("select ptso.skuOption from ProductTypeSkuOption ptso where  ptso.productType.productTypeId=? order by ptso.sortOrder asc", productTypeId);
		return skuOptions;
	}
	
	/*
	 * (non-Javadoc)
	 * @see com.probiz.estore.product.dao.SkuOptionDao#getNumOfQuickSearchOptionsByProductTypeId(java.lang.Integer)
	 */
    public Long getNumOfQuickSearchOptionsByProductTypeId(Integer productTypeId){
    	return (Long)this.findUnique("select count(ptso.productTypeSkuOptionId) from ProductTypeSkuOption ptso where ptso.productType.productTypeId = ? and ptso.isQuickSearch =1" ,productTypeId);
    }
    /*
     * (non-Javadoc)
     * @see com.probiz.estore.product.dao.SkuOptionDao#getQuickSearchSkuOptionsByProductTypeId(java.lang.Integer)
     */
    @SuppressWarnings("unchecked")
    public List<SkuOption> getQuickSearchSkuOptionsByProductTypeId(Integer productTypeId){
    	List<SkuOption> skuOptions=findByHql("select ptso.skuOption from ProductTypeSkuOption ptso where  ptso.productType.productTypeId=? and ptso.isQuickSearch =1 order by ptso.sortOrder asc", productTypeId);
		return skuOptions;
    }
    /*
     * (non-Javadoc)
     * @see com.probiz.estore.product.dao.SkuOptionDao#getSizeOfProductSkuOptionValue(java.lang.Integer)
     */
    public Long getSizeOfProductSkuOptionValue(Integer skuOptionId){
    	return this.countByHql("select count(o.productSkuOptionValueId) from ProductSkuOptionValue o where o.skuOptionValue.skuOption.skuOptionId=?", skuOptionId);
    }
    
    /*
     * (non-Javadoc)
     * @see com.probiz.estore.product.dao.SkuOptionDao#getSizeOfProductSkuOptionValueByProductTypeAndSkuOption(java.lang.Integer, java.lang.Integer)
     */
    public Long getSizeOfProductSkuOptionValueByProductTypeAndSkuOption(Integer productTypeId,Integer skuOptionId){
    	return this.countByHql("select count(o.productSkuOptionValueId) from ProductSkuOptionValue o where o.productSku.product.productType.productTypeId = ? and o.skuOptionValue.skuOption.skuOptionId=?", productTypeId,skuOptionId);
    }



}
